﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Styx;
using Styx.Common;
using Styx.CommonBot;
using Styx.CommonBot.Routines;
using Styx.WoWInternals;
using Styx.WoWInternals.WoWObjects;



namespace Mufasa
{
    public class Mufasa : CombatRoutine
    {
        public override string Name { get { return "Mufasa - Feral & Guardian CC 1.0"; } }
        public override WoWClass Class { get { return WoWClass.Druid; } }
        public static LocalPlayer Me { get { return StyxWoW.Me; } }
        private void slog(string format, params object[] args) { Logging.Write(format, args); }

        public override bool WantButton { get { return true; } }
        public override void Initialize()
        {
                Logging.Write(" -> Mufasa 1.0 <- ");
                Logging.Write(" -> A LazyRaider Feral CC <- ");
        }

        public override void OnButtonPress()
        {
            Logging.Write(" -> No settings yet sorry! <- ");
        }

        #region Cast Spell Method
        public static bool CastSpell(string spellName)
        {
            if (SpellManager.CanCast(spellName))
            {
                if (SpellManager.HasSpell(spellName) && SpellManager.Spells[spellName].CooldownTimeLeft.TotalMilliseconds < 250)
                {
                    SpellManager.Cast(spellName);            
                    return true;
                }
            }
            return false;
        }
        #endregion  

        #region MyDebuffTime
        //Used for checking how the time left on "my" debuff
        private int MyDebuffTime(String spellName, WoWUnit unit)
        {
            {
                if (unit.HasAura(spellName))
                {
                    var auras = unit.GetAllAuras();
                    foreach (var a in auras)
                    {
                        if (a.Name == spellName && a.CreatorGuid == Me.Guid)
                        {
                            return a.TimeLeft.Seconds;
                        }
                    }
                }
            }
            return 0;
        }
        #endregion

        #region Combat Rotation
        public override void Combat()  {
            // NOT TESTED
            if (Me.ComboPoints < 5 && Me.CurrentEnergy > 40 && Me.CurrentTarget.HasAura("Rake")) { CastSpell("Shred"); }
            if (Me.CurrentEnergy > 35 && MyDebuffTime("Rake", Me.CurrentTarget) < 6) { CastSpell("Rake"); }
            if (Me.ComboPoints == 5 && Me.CurrentEnergy > 40 && !Me.CurrentTarget.HasAura("Rip") || MyDebuffTime("Rip", Me.CurrentTarget) <= 8) { CastSpell("Rip"); }
            if (Me.ComboPoints == 5 && Me.CurrentEnergy > 40 && Me.CurrentTarget.HasAura("Rake") && Me.CurrentTarget.HasAura("Rip") && MyDebuffTime("Rip", Me.CurrentTarget) > 20) { CastSpell("Savage Roar"); }
            //When a bit low on energy
            if (!Me.HasAura("Tiger's Fury")
                && MyDebuffTime("Rip", Me.CurrentTarget) <= 8
                && MyDebuffTime("Rake", Me.CurrentTarget) <= 8
                && MyDebuffTime("Savage Roar", Me) < 15)

            {
                CastSpell("Tiger's Fury");
            }
            //When we need to burst
            if (Me.CurrentEnergy > 70
                && MyDebuffTime("Rake", Me.CurrentTarget) > 10
                && MyDebuffTime("Rip", Me.CurrentTarget) > 20)
            {
                CastSpell("Berserk");
            }
            // When nothing else to do
            if (Me.ComboPoints == 5 && Me.CurrentEnergy > 45
                && MyDebuffTime("Rake", Me.CurrentTarget) > 5
                && MyDebuffTime("Rip", Me.CurrentTarget) > 20)
            {
                CastSpell("Ferocious Bite");
            }
      
        }
        #endregion

    }

}
